package com.golxen.framework.db;


import com.golxen.framework.common.ConfigPlugin;

public class DbPlugin {

    static DbPlugin instance = null;

    public static void start() {
        if (instance != null) {
            return;
        }

        instance = new DbPlugin();

        if (!ConfigPlugin.active()) {
            throw new RuntimeException("plugin depend on ConfigPlugin not active!!");
        }

        DBManager.initConfig();

    }

    public static boolean active() {
        return instance != null;
    }

    public static <T> T getDaoImpl(Class<T> cls) {
        T newInstance;
        try {
            newInstance = cls.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return newInstance;
    }

}
